require "Common/define"
require "Logic/Config"
require "Common/functions"

RedDotsActivityCentreHandler = {};
local this = RedDotsActivityCentreHandler;

function RedDotsActivityCentreHandler.init()
    CloseEvent(Config.EventType.Fresh_Active, this.update);
    CloseEvent(Config.EventType.Fresh_SevenDay, this.update);
    CloseEvent(Config.EventType.Fresh_TaskInfo, this.update);
    CloseEvent(Config.EventType.Res_TaskInfo_Get, this.update);
    CloseEvent(Config.EventType.Fresh_NewStage, this.update);
    ListenEvent(Config.EventType.Fresh_NewStage, this.update);
    ListenEvent(Config.EventType.Fresh_TaskInfo, this.update);
    ListenEvent(Config.EventType.Res_TaskInfo_Get, this.update);
    ListenEvent(Config.EventType.Fresh_SevenDay, this.update);
    ListenEvent(Config.EventType.Fresh_Active, this.update);
    return this;
end

--参数1：指定活动Id，nil代表检查活动中心
---活动红点
function RedDotsActivityCentreHandler.getFlag(...)
    this.activeTypeList = {EnumConst.ActiveShowType.TimeLimit, EnumConst.ActiveShowType.Forever, EnumConst.ActiveShowType.ActiveCenter}
    local flag = Config.RedDotsFlagState.None;
    --if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.City, false) or param ~= nil then
        local tabId, type = ...;
        local tableData = {};
        if tabId == nil then
            if type == nil then
                tableData = {};
                for k, v in pairs(this.activeTypeList) do
                    for key, value in pairs(logicMgr.ActiveManager.getActiveEntranceDataListByType(v)) do
                        table.insert(tableData, value);
                    end
                end
            else
                tableData = logicMgr.ActiveManager.getActiveEntranceDataListByType(type);
            end
        else
            table.insert(tableData, logicMgr.ActiveManager.getActiveServerDataList(tabId));
        end
        for k, v in pairs(tableData) do
            --去除累充98红点关注
            if v.activeId ~=11004 then
                local itemTableData, serverData = logicMgr.ActiveManager.getActiveData(v.activeId);
                if serverData ~= nil then
                    if serverData.redDots then
                        flag = Config.RedDotsFlagState.Needful;
                        break;
                    end
                end
            end
        end
    --end
    return flag;
end

function RedDotsActivityCentreHandler.update()
    RedDotsManager.addBroadcast(Config.RedDotsType.ActivityCentre);
end